package dper.study.codes.common.testusage;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.commons.collections.IterableMap;
import org.apache.commons.collections.iterators.FilterIterator;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * Created by leichen on 2017/5/5.
 */
public class TestGuava {
    public static void main(String[] argv){
        List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom");
        Iterable<String> result = Iterables.filter(names, Predicates.containsPattern("a"));
        Predicate<String> predicate = new Predicate<String>() {
            public boolean apply(String input) {
                return input.startsWith("A") || input.startsWith("T");
            }
        };

        Function<String, Integer> func = new Function<String,Integer>(){
            public Integer apply(String input) {
                return input.length();
            }
        };

        List<String> names_filter = Lists.newArrayList("John", "Jane", "Adam", "Tom");
        List<Integer> nameLengths = Lists.transform(names,func) ;
        for(String name:result){
            System.out.println(name) ;
        }

        for(Integer namel:nameLengths){
            System.out.println(namel) ;
        }
    }
}
